package org.jash.ting13.home

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import org.jash.ting13.R
import org.jash.ting13.BR
import org.jash.ting13.entity.SearchEntity
import org.jash.utils.CommonViewHolder
import org.jash.utils.log

class SearchAdapter:PagingDataAdapter<SearchEntity, CommonViewHolder>(SearchCallback) {
    override fun onBindViewHolder(holder: CommonViewHolder, position: Int) {
        holder.binding.setVariable(BR.entity, getItem(position))
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommonViewHolder =
        CommonViewHolder(DataBindingUtil.inflate(LayoutInflater.from(parent.context), R.layout.item_search, parent, false))
}
object SearchCallback:DiffUtil.ItemCallback<SearchEntity>() {
    override fun areItemsTheSame(oldItem: SearchEntity, newItem: SearchEntity): Boolean = oldItem.url == newItem.url

    override fun areContentsTheSame(oldItem: SearchEntity, newItem: SearchEntity): Boolean = oldItem == newItem

}